package com.ibm.risk.irmp.workflow.client.flowable.api;

import com.ibm.risk.irmp.workflow.client.flowable.ApiClient;

import com.ibm.risk.irmp.workflow.client.flowable.model.DataResponseListMapStringObject;
import com.ibm.risk.irmp.workflow.client.flowable.model.TableMetaData;
import com.ibm.risk.irmp.workflow.client.flowable.model.TableResponse;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.util.UriComponentsBuilder;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;


@Component("com.ibm.risk.irmp.flowable.api.DatabaseTablesApi")
public class DatabaseTablesApi {
    private ApiClient apiClient;

    public DatabaseTablesApi() {
        this(new ApiClient());
    }

    @Autowired
    public DatabaseTablesApi(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    public ApiClient getApiClient() {
        return apiClient;
    }

    public void setApiClient(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    /**
     * Get a single table
     *
     * <p><b>200</b> - Indicates the table exists and the table count is returned.
     * <p><b>404</b> - Indicates the requested table does not exist.
     * @param tableName The tableName parameter
     * @return TableResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public TableResponse getTable(String tableName) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'tableName' is set
        if (tableName == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'tableName' when calling getTable");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("tableName", tableName);
        String path = UriComponentsBuilder.fromPath("/management/tables/{tableName}").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<TableResponse> returnType = new ParameterizedTypeReference<TableResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Get row data for a single table
     *
     * <p><b>200</b> - Indicates the table exists and the table row data is returned
     * <p><b>404</b> - Indicates the requested table does not exist.
     * @param tableName The tableName parameter
     * @param start Index of the first row to fetch. Defaults to 0.
     * @param size Number of rows to fetch, starting from start. Defaults to 10.
     * @param orderAscendingColumn Name of the column to sort the resulting rows on, ascending.
     * @param orderDescendingColumn Name of the column to sort the resulting rows on, descending.
     * @return DataResponseListMapStringObject
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DataResponseListMapStringObject getTableData(String tableName, Integer start, Integer size, String orderAscendingColumn, String orderDescendingColumn) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'tableName' is set
        if (tableName == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'tableName' when calling getTableData");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("tableName", tableName);
        String path = UriComponentsBuilder.fromPath("/management/tables/{tableName}/data").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "start", start));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "size", size));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "orderAscendingColumn", orderAscendingColumn));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "orderDescendingColumn", orderDescendingColumn));

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DataResponseListMapStringObject> returnType = new ParameterizedTypeReference<DataResponseListMapStringObject>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Get column info for a single table
     *
     * <p><b>200</b> - Indicates the table exists and the table column info is returned.
     * <p><b>404</b> - Indicates the requested table does not exist.
     * @param tableName The tableName parameter
     * @return TableMetaData
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public TableMetaData getTableMetaData(String tableName) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'tableName' is set
        if (tableName == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'tableName' when calling getTableMetaData");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("tableName", tableName);
        String path = UriComponentsBuilder.fromPath("/management/tables/{tableName}/columns").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<TableMetaData> returnType = new ParameterizedTypeReference<TableMetaData>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     *  List tables
     *
     * <p><b>200</b> - Indicates the request was successful.
     * @return List&lt;TableResponse&gt;
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public List<TableResponse> listTables() throws RestClientException {
        Object postBody = null;

        String path = UriComponentsBuilder.fromPath("/management/tables").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<List<TableResponse>> returnType = new ParameterizedTypeReference<List<TableResponse>>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
}
